package com.neusoft.neu24.nep.controller;

import com.neusoft.neu24.nep.entity.Author;
import com.neusoft.neu24.nep.entity.web.CommonResult;
import com.neusoft.neu24.nep.handler.AuthorHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/a")
public class AuthorController {
    @Autowired
    private AuthorHandler authorHandler;

    @PostMapping("/save")
    public  Mono<CommonResult<Author>> save( Author author)
    {
       return  authorHandler.save(author).map(  a -> CommonResult.success(a) );
    }


    @GetMapping("q/name/{name}")

    public  Mono<CommonResult> findUsersByName(@PathVariable("name") String name){
        return authorHandler.findAuthorByName(name).map( a -> CommonResult.success(a)  ) ;
    }


    @GetMapping("q/all")

    public Mono<CommonResult> findAll(){
        return authorHandler.findAll().collectList().map( a -> CommonResult.success(a)  ) ;
    }

}
